package com.hw01.controller;

import com.hw01.common.Result;
import com.hw01.common.ResultPage;
import com.hw01.dto.OrganizationAddDto;
import com.hw01.dto.OrganizationQueryDto;
import com.hw01.dto.OrganizationUpdateDto;
import com.hw01.service.OrganizationService;
import com.hw01.vo.OrganizationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 部门管理
 **/
@RestController
@Api("部门管理")
@RequestMapping("/organization")
public class OrganizationController {

    @Autowired
    OrganizationService organizationService;

    @PostMapping("/page")
    @ApiOperation("按条件查询部门(分页)")
    @ResponseBody
    public ResultPage<OrganizationVo> getOrganizationPage(@RequestBody OrganizationQueryDto dto) {
        return organizationService.getOrganizationPage(dto);
    }

    @PostMapping("/add")
    @ApiOperation("新增部门")
    public Result<Boolean> add(@RequestBody OrganizationAddDto dto) {
        return organizationService.add(dto);
    }

    @PostMapping("/update")
    @ApiOperation("修改部门信息")
    public Result<Boolean> update(@RequestBody OrganizationUpdateDto dto) {
        return organizationService.update(dto);
    }

    @GetMapping("/del")
    @ApiOperation("删除部门")
    public Result<Boolean> delete(@ApiParam(value = "部门id", required = true) Long id) {
        return organizationService.delete(id);
    }

    @GetMapping("/setOrgLeader")
    @ApiOperation("设置部门领导")
    public Result<Boolean> setOrgLeader(@ApiParam(value = "部门id", required = true) Long orgId,
        @ApiParam(value = "员工id", required = true) Long userId) {
        return organizationService.setOrgLeader(orgId, userId);
    }

}
